(function() {
	'use strict';
	var i = 0
	var focusTpl = "\r\n\r\n<div class=\"layui-carousel focus\" id=\"focus\">\r\n    <div carousel-item>\r\n\t\t{{#  layui.each(d.focusList, function(index, item){ }}\r\n\t\t\t<div class=\"focus-item\">\r\n\t\t\t\t<img itemid='{{item.id}}' src=\"{{item.src}}\" alt=\"{{item.text}}\">\r\n\t\t\t\t<p class=\"focus-item-text\">{{item.text}}</p>\r\n\t\t\t</div>\r\n\t\t{{#  }); }}\r\n    </div>\r\n</div>";

	var newsTpl1 = "<ul class=\"news-content-lsit livelihood\">\r\n\t\r\n\t {{#  layui.each(d.Rules, function(index, item){ }}\r\n\t\t{{#if(index >= 8){ }}\r\n\t\t{{# }else{}}\r\n\t\t\t<li class=\"clearfix\" itemid='{{item.id}}'><a href=\"javascript:;\" ><i class=\"fa fa-list-alt\"></i><span class=\"title\">{{item.title}}</span><i class=\"time\">{{item.time}}</i></a></li>\r\n\t\t{{#} }}\r\n\t{{#  }); }}\r\n</ul>";

	var newsTpl2 = "<ul class=\"news-content-lsit policy\">\r\n\t\r\n\t{{#  layui.each(d.Standard, function(index, item){ }}\r\n\t\t{{#if(index >= 8){ }}\r\n\t\t{{# }else{}}\r\n\t\t\t<li class=\"clearfix\" itemid='{{item.id}}'><a href=\"javascript:;\"><i class=\"fa fa-list-alt\"></i><span class=\"title\">{{item.title}}</span><i class=\"time\">{{item.time}}</i></a></li>\r\n\t\t{{#} }}\r\n\t{{#  }); }}\r\n</ul>";

	var newsTpl3 = "<ul class=\"news-content-lsit affairs\">\r\n\t\r\n\t{{#  layui.each(d.companyNews, function(index, item){ }}\r\n\t\t{{#if(index >= 6){ }}\r\n\t\t{{# }else{}}\r\n\t\t\t<li class=\"clearfix\" itemid='{{item.id}}'><a href=\"javascript:;\"><i class=\"fa fa-list-alt\"></i><span class=\"title\">{{item.title}}</span><i class=\"time\">{{item.time}}</i></a></li>\r\n\t\t{{#} }}\r\n\t{{#  }); }}\r\n</ul>";

	var newsTpl4 = "<ul class=\"news-content-lsit government \">\r\n\t\r\n\t{{#  layui.each(d.societyNews, function(index, item){ }}\r\n\t\t{{#if(index >= 6){ }}\r\n\t\t{{# }else{}}\r\n\t\t\t<li class=\"clearfix\" itemid='{{item.id}}'><a href=\"javascript:;\"><i class=\"fa fa-list-alt\"></i><span class=\"title\">{{item.title}}</span><i class=\"time\">{{item.time}}</i></a></li>\r\n\t\t{{#} }}\r\n\t{{#  }); }}\r\n</ul>";

	/*公告公示*/
    var newsTpl5 = "<ul class=\"news-content-lsit affairs \">\r\n\t\r\n\t{{#  layui.each(d.companyGsggs, function(index, item){ }}\r\n\t\t{{#if(index >= 6){ }}\r\n\t\t{{# }else{}}\r\n\t\t\t<li class=\"clearfix\" itemid='{{item.id}}'><a href=\"javascript:;\"><i class=\"fa fa-list-alt\"></i><span class=\"title\">{{item.title}}</span><i class=\"time\">{{item.time}}</i></a></li>\r\n\t\t{{#} }}\r\n\t{{#  }); }}\r\n</ul>";

    /*政策法规*/
    var newsTpl6 = "<ul class=\"news-content-lsit affairs \">\r\n\t\r\n\t{{#  layui.each(d.companyViews, function(index, item){ }}\r\n\t\t{{#if(index >= 6){ }}\r\n\t\t{{# }else{}}\r\n\t\t\t<li class=\"clearfix\" itemid='{{item.id}}'><a href=\"javascript:;\"><i class=\"fa fa-list-alt\"></i><span class=\"title\">{{item.title}}</span><i class=\"time\">{{item.time}}</i></a></li>\r\n\t\t{{#} }}\r\n\t{{#  }); }}\r\n</ul>";

    /* 便民服务按钮 */
    var serviceTpl1 = "{{# layui.each(d.serviceInfos, function(index, item){ }}{{#if(index >= 15){ }}{{# }else{}}<button itemid='{{item.service_id}}'><a href=\"javascript:;\"><i class=\"fa fa-file-text-o\" aria-hidden=\"true\"></i>{{item.service_name}}</a></button>{{#} }}{{# }); }}";

    var data = "";
    $.ajax({
        url : "/CivilAffairs/news/getNews",
        type : "post",
		async : false,
        dataType : "json",
        success : function(result) {
        	if(checkResult(result)){
                data = result.data;
			}
        },
        error : function() {
            alert("系统异常,请稍后重试");
        }
    });

	layui.use([ "jquery", 'laytpl', 'carousel', 'element' ,'layer'], function() {
		var laytpl = layui.laytpl;
		var carousel = layui.carousel;
		var element = layui.element;
		var $ = layui.$; //轮播图
		var layer = layui.layer;

		//提示信息
        if(window.sessionStorage.getItem("showTitle") != "true"){
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true,
                skin: 'alert-div',
                content: '<div class="alert-div"><p>尊敬的用户你好:</p><p>&nbsp;&nbsp;&nbsp;&nbsp;为了更好的浏览体验，建议您使用360浏览器、火狐浏览器、谷歌浏览器。</p></div>',
                success: function (layero,index) {
                    setTimeout(function () {
                        layer.close(index);
                    },3000);
                }
            });
            window.sessionStorage.setItem("showTitle","true");
        }

		var getTpl1 = focusTpl,
			view1 = document.getElementById('focusWrap');
		laytpl(getTpl1).render(data, function(html) {
			view1.innerHTML = html;carousel.render({
				elem : '#focus',
				width : '496sp',
				arrow : 'always',
				indicator : "outside",
                interval : 5000
			});
		}); //新闻
		var Rules_getTpl = newsTpl1;
		var Standard_getTpl = newsTpl2;
		laytpl(Rules_getTpl).render(data["news"], function(html) {
			element.tabAdd('news', {
				title : '最新动态',
				content : html,
				id : 'lay-id-0'
			});
		});laytpl(Standard_getTpl).render(data["news"], function(html) {
			element.tabAdd('news', {
				title : '民政要闻',
				content : html,
				id : 'lay-id-1'
			});
		});$("#app .news ul.layui-tab-title li").on("mouseenter", function() {
			console.log($(this).index());$(this).addClass("layui-this").siblings("li").removeClass("layui-this");$(this).parent("ul.layui-tab-title").next(".layui-tab-content").children(".layui-tab-item").eq($(this).index()).addClass("layui-this  layui-show").siblings().removeClass("layui-this layui-show");
		});$("#app .news ul.layui-tab-title li").first().click(); //企业新闻&&社会新闻
		var companyNews3 = newsTpl3;
		var societyNews4 = newsTpl4;

		var companyGsggs1 = newsTpl5;
		var companyViews5 = newsTpl6;

		//政策法规
		//var company_view = document.getElementById('companyNewsContent');
		var society_view = document.getElementById('societyNewsContent');

		//公示公告
		var companyGsgg_view = document.getElementById('companyGsggsContent');
		//媒体关注
		var companyView_view = document.getElementById('companyViewsContent');

		// laytpl(companyNews3).render(data, function(html) {
		// 	company_view.innerHTML = html;
		// });
		// laytpl(societyNews4).render(data, function(html) {
		// 	society_view.innerHTML = html;
		// });

        laytpl(companyGsggs1).render(data, function(html) {
            companyGsgg_view.innerHTML = html;
        });

        laytpl(companyViews5).render(data, function(html) {
            companyView_view.innerHTML = html;
        });

        //便民服务按钮加载
        laytpl(serviceTpl1).render(data,function(html){
            document.getElementById("service1").innerHTML = html;
        });

        //举报按钮
		$(".report").click(function () {
			window.open("../report/index.html?index=0");
		});
		//局长信箱
        $(".mailBox").click(function () {
            window.open("../report/index.html?index=1");
        });

	});
	//最新动态...和首页轮播图点击显示详情先不显示 #focusWrap img
	$("body").on('click', '.livelihood li,.policy li,.affairs li', function() {
        window.open("./detail/index.html?id="+$(this).attr("itemid"));
	});
    //便民服务按钮点击
    $("body").on('click', '#service1 button', function() {
        window.open("./server/index.html?id="+$(this).attr("itemid"));
    });

	$("body").on('click', '.info-btn button', function() {

		//工作程序
		if ($(this).index() == 2) {
			window.open("./server/index.html");
		}else {
			//信息公开指南&领导机构
            var id = 0==$(this).index()?"information_id":"authorities_id";
			window.open("./detail/index.html?id="+id);
		}
	});

	//最新动态&民政要闻的more button
    $("body").on('click', '.more-button', function() {
    	var newType = $(this).attr("itemtype");
    	if("dynamic"==newType){
            var newTypeContent = $(".news .layui-this").html();
            newType = "民政要闻" == newTypeContent?"civil":newType;
		}
        //console.log(newType);
		window.open("./allnews/index.html?type="+newType);
	});
    //惠民资金的按钮
    $("body").on('click', '.fpgjzygxpt-btn button', function() {
        window.open("./organ/index.html?flag=beneficiary&index=" + ($(this).index()+1));
    });
}());
